package com.es.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author SeniorTong丶
 * @Date 2021/11/22 14:00
 * @Version 1.0
 * @Remark
 */
@Data
public class RestResult implements Serializable {

    private static final long serialVersionUID = -1L;

    private Integer code;

    private String msg;

    private Object data;

    public RestResult() {
    }

    public RestResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public void setResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static RestResult success() {
        RestResult result = new RestResult();
        result.setResultCode(200, "操作成功");
        return result;
    }

    public static RestResult error() {
        RestResult result = new RestResult();
        result.setResultCode(500, "操作失败");
        return result;
    }

    public static RestResult error(String msg) {
        RestResult result = new RestResult();
        result.setResultCode(500, msg);
        return result;
    }

    public static RestResult success(Object data) {
        RestResult result = new RestResult();
        result.setResultCode(200, "操作成功");
        result.setData(data);
        return result;
    }

    public static RestResult failure(Integer code, String msg) {
        RestResult result = new RestResult();
        result.setResultCode(code, msg);
        return result;
    }

    public static RestResult failure(Integer code, String msg, Object data) {
        RestResult result = new RestResult();
        result.setResultCode(code, msg);
        result.setData(data);
        return result;
    }

}
